//
//  EmergencyTableViewCell.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/14.
//

#import "EmergencyTableViewCell.h"

@implementation EmergencyTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        self.topNameLab = [Utility createLabel:[UIFont fontWithName:kFuturaBold size:15] color:[UIColor colorWithHexString:@"#022D06"]];
        self.topNameLab.textAlignment = 1;
        [self.contentView addSubview:self.topNameLab];
        [self.topNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(kScreenWidth/2 - 190/2));
            make.top.equalTo(self.contentView.mas_top);
            make.height.equalTo(@45);
            make.width.equalTo(@190);
            
        }];
        
        self.ic1 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.ic1];
        [self.ic1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.topNameLab.mas_left);
            make.width.with.height.equalTo(@20);
            make.centerY.equalTo(self.topNameLab.mas_centerY);
        }];
        
        self.ic2 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.ic2];
        [self.ic2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topNameLab.mas_right);
            make.width.with.height.equalTo(@20);
            make.top.equalTo(self.ic1.mas_top);
        }];
        
        self.bottomImgView1 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.bottomImgView1];
        self.bottomImgView1.userInteractionEnabled = YES;
        [self.bottomImgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.height.equalTo(@68);
            make.top.equalTo(self.topNameLab.mas_bottom).offset(22);
        }];
        
        self.topImgView1 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.topImgView1];
        self.topImgView1.userInteractionEnabled = YES;
        [self.topImgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(72);
            make.right.equalTo(self.contentView.mas_right).offset(-72);
            make.height.equalTo(@44);
            make.top.equalTo(self.topNameLab.mas_bottom).offset(2);
        }];
        
        self.titleLab1 = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:14] color:[UIColor colorWithHexString:@"#FFEFC0"]];
        self.titleLab1.textAlignment = 1;
        [self.topImgView1 addSubview:self.titleLab1];
        self.titleLab1.adjustsFontSizeToFitWidth = YES;
        [self.titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topImgView1.mas_left);
            make.right.equalTo(self.topImgView1.mas_right);
            make.top.equalTo(self.topImgView1.mas_top);
            make.bottom.equalTo(self.topImgView1.mas_bottom);
        }];
        
        self.textFiled1 = [[CreditTextFiled alloc] init];
        self.textFiled1.textColor = [UIColor colorWithHexString:@"#022D06"];
        self.textFiled1.font = [UIFont fontWithName:kFuturaMedium size:14];
        self.textFiled1.textAlignment = 1;
        self.textFiled1.delegate = self;
        [self.bottomImgView1 addSubview:self.textFiled1];
        [self.textFiled1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomImgView1.mas_left).offset(30);
            make.right.equalTo(self.bottomImgView1.mas_right).offset(-30);
            make.bottom.equalTo(self.bottomImgView1.mas_bottom);
            make.top.equalTo(self.titleLab1.mas_bottom);
        }];
       
        self.textFiled1.userInteractionEnabled = YES;
        
        self.arrowImgView1 = [[UIImageView alloc] init];
        [self.bottomImgView1 addSubview:self.arrowImgView1];
        [self.arrowImgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@16);
            make.height.equalTo(@14);
            make.right.equalTo(self.bottomImgView1.mas_right).offset(-12);
            make.centerY.equalTo(self.textFiled1.mas_centerY);
        }];
        
        
        
        self.bottomImgView2 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.bottomImgView2];
        self.bottomImgView2.userInteractionEnabled = YES;
        [self.bottomImgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.height.equalTo(@68);
            make.top.equalTo(self.bottomImgView1.mas_bottom).offset(37);
        }];
        
        self.topImgView2 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.topImgView2];
        self.topImgView2.userInteractionEnabled = YES;
        [self.topImgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(72);
            make.right.equalTo(self.contentView.mas_right).offset(-72);
            make.height.equalTo(@44);
            make.top.equalTo(self.bottomImgView1.mas_bottom).offset(17);
        }];
        
        self.titleLab2 = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:14] color:[UIColor colorWithHexString:@"#FFEFC0"]];
        self.titleLab2.textAlignment = 1;
        [self.topImgView2 addSubview:self.titleLab2];
        self.titleLab2.adjustsFontSizeToFitWidth = YES;
        [self.titleLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topImgView2.mas_left);
            make.right.equalTo(self.topImgView2.mas_right);
            make.top.equalTo(self.topImgView2.mas_top);
            make.bottom.equalTo(self.topImgView2.mas_bottom);
        }];
        
        self.textFiled2 = [[CreditTextFiled alloc] init];
        self.textFiled2.textColor = [UIColor colorWithHexString:@"#022D06"];
        self.textFiled2.font = [UIFont fontWithName:kFuturaMedium size:14];
        self.textFiled2.textAlignment = 1;
        self.textFiled2.delegate = self;
        [self.bottomImgView2 addSubview:self.textFiled2];
        [self.textFiled2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomImgView2.mas_left).offset(30);
            make.right.equalTo(self.bottomImgView2.mas_right).offset(-30);
            make.bottom.equalTo(self.bottomImgView2.mas_bottom);
            make.top.equalTo(self.titleLab2.mas_bottom);
        }];
       
        self.textFiled2.userInteractionEnabled = YES;
        
        self.arrowImgView2 = [[UIImageView alloc] init];
        [self.bottomImgView2 addSubview:self.arrowImgView2];
        [self.arrowImgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@16);
            make.height.equalTo(@14);
            make.right.equalTo(self.bottomImgView2.mas_right).offset(-12);
            make.centerY.equalTo(self.textFiled2.mas_centerY);
        }];
        
        
        
        
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap1)];
        [self.textFiled1 addGestureRecognizer:tap1];
        
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap2)];
        [self.textFiled2 addGestureRecognizer:tap2];
        
        
        
        
        
    }
    return self;
}

- (void)clickTap1{
    if (_clickTap1Block) {
        _clickTap1Block(self.model);
    }
}

- (void)clickTap2{
    if (_clickTap2Block) {
        _clickTap2Block(self.model);
    }
}

- (void)setModel:(EmergencyModel *)model{
    _model = model;
    
    
    self.ic1.image = [UIImage imageNamed:@"icon_leftTips"];
    self.ic2.image = [UIImage imageNamed:@"icon_rightTips"];
    
    self.topImgView1.image = [UIImage imageNamed:@"icon_per2"];
    self.bottomImgView1.image = [UIImage imageNamed:@"icon_per3"];
    self.arrowImgView1.image = [UIImage imageNamed:@"icon_idf12"];
    
    self.titleLab1.text = @"Relationship With Customers";
    
    self.textFiled1.placeholder = @"Please select a relationship";
    
    self.textFiled1.text  = esString(model.locks);
    
    NSMutableAttributedString *placeholderString1 = [[NSMutableAttributedString alloc] initWithString:self.textFiled1.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#638473"]}];
    self.textFiled1.attributedPlaceholder = placeholderString1;
    
    
    self.topImgView2.image = [UIImage imageNamed:@"icon_per2"];
    self.bottomImgView2.image = [UIImage imageNamed:@"icon_per3"];
    self.arrowImgView2.image = [UIImage imageNamed:@"icon_idf12"];

    self.titleLab2.text = @"Contact Information";
    self.textFiled2.placeholder = @"Name - Phone Number";

    if (!PMStringIsEmpty(model.cambridge) & !PMStringIsEmpty(model.shave)) {
        self.textFiled2.text  = [NSString stringWithFormat:@"%@ - %@",esString(model.cambridge),esString(model.shave)];
    }
    else{
        self.textFiled2.text = @"";
    }
    
    NSMutableAttributedString *placeholderString2 = [[NSMutableAttributedString alloc] initWithString:self.textFiled2.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#638473"]}];
    self.textFiled2.attributedPlaceholder = placeholderString2;
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
